home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / batch / batcher9 / key-fake.doc < prev    next >
Encoding:
Text File  |  1986-02-26  |  14.3 KB  |  310 lines

  1.                              KEY-FAKE.DOC
  2.        (PC Magazine Vol 4 No 26 December 24, 1985 by C. Petzold)
  3.  
  4.      "Press any key to begin" is a tolerable but minor nuisance.  But
  5. can you live with programs that don't maintain configuration files and
  6. required you to enter your printer port number before you start?  Or
  7. all those that should have been designed to accept commands but which
  8. walk you through a series of questions and answers instead?  Do you
  9. find yourself entering the same few start-up commands every time you
  10. use them?
  11.  
  12.      Usually there's not too much you can do about these annoying
  13. program preliminaries.  YOu may have created batch files to change
  14. subdirectories and save much repetitive typing, but normal batch files
  15. don't help once your program begins to execute.
  16.  
  17.      KEY-FAKE is a utility designed to extend the usefulness of your
  18. batch files by letting you supply all the necessary initial keystrokes
  19. to programs automatically.  In addition to handling program
  20. preliminaries, KEY-FAKE can even be made to run a whole program
  21. without any keyboard intervention on your part.  Hard disk systems
  22. users often assemble a collection of short batch files (often with
  23. one-letter names) that help to navigate through the invariable maze of
  24. subdirectories and programs.  Yet once a program begins executing, it's
  25. on its own, and batch file processing doesn't take over again until you
  26. exit the program.
  27.  
  28.      KEY-FAKE extends the power of batch files by filling this gap.
  29. With KEY-FAKE you can put program commands in your batch files as a
  30. series of keystrokes.  When the batch file loads the program, these
  31. keystrokes are interpreted just as if you had typed them yourself.
  32.  
  33.      From one perspective, it would seem that this facility is provided
  34. by DOS 2.0 and later versions.  It's called redirection of standard
  35. input, and it permits you to substitute a file for the normal keyboard
  36. input.  Unfortunately, while redirection of standard input is useful in
  37. certain applications, it is not designed for and cannot be used to take
  38. care of your program preliminaries.
  39.  
  40.      For one thing, redirection only works with programs that use DOS
  41. function calls to get keyboard information.  Most large programs use
  42. the BIOS Interrupt 16h for keyboard input instead.  Another problem is
  43. that redirection of standard input is al all-or-nothing proposition.
  44. It doesn't switch back to the real keyboard when the redirected file
  45. ends.  Thus, if standard input is redirected from a file that is
  46. exhausted while the program is still running, the program will hang.
  47. The only keystroke command to which the machine will then respond is
  48. the drastic reboot.
  49.  
  50.      Unlike redirection of standard input, KEY-FAKE works with programs
  51. that use the BIOS Interrupt 16h for keyboard input.  More importantly,
  52. once KEY-FAKE runs out of keystrokes, it relinquishes control and lets
  53. you continue with the typing.
  54.  
  55.  
  56.  
  57.      The best way to understand how to use KEY-FAKE and what is does is
  58. by looking at a few simple examples.  Suppose that every time you enter
  59. BASICA you execute a COLOR command to create a blue border and
  60. background with yellow letters.  With KEY-FAKE, you could create a
  61. two-line batch file (perhaps called B.BAT) to load BASICA:
  62.  
  63.           KEY-FAKE "COLOR 14,1,1" 13 "CLS" 13
  64.           BASICA
  65.  
  66.      After BASICA loads, it begins to check for commands coming from
  67. the keyboard.  The first keystrokes it reads, in this case, are those
  68. that come from the KEY-FAKE parameter.  Rule number one, then, is that
  69. KEY-FAKE must be executed before the program that will use the
  70. keystrokes.
  71.  
  72.      Anything placed in quotation marks in the KEY-FAKE parameter is
  73. interpreted as normal text, just as if you typed it in at the keyboard.
  74. Simple decimal numbers (like the 13) are ASCII codes for non-printable
  75. characters or control codes.  A 13 is the Enter key, for example.
  76. Similarly, a 27 is the Escape key, a 9 the Tab key, and an 8 is the
  77. Backspace key.
  78.  
  79.      You may use single quotes or double quotes to delimit a test
  80. string.  This is handy if you have to simulate a typed quote sign.
  81. If your text string must include a double quote sign, for instance,
  82. use single quotes as delimiters.  (This is a neat trick used by the
  83. IBM and Microsoft Macro Assemblers to solve the perennial quote-
  84. within-quote problem.)
  85.  
  86.      You may also include the "extended ASCII" keys (decimal codes 128
  87. through 255) as part of the KEY-FAKE parameter.  These include the
  88. function keys, cursor movement keys, Alt-letter keys, Alt-number keys,
  89. Ins, and Del.  These keys are specified in KEY-FAKE by the "at" sign
  90. (@) followed immediately by the extended ASCII code.  For instance, if
  91. you usually use the F3 key to load a program when you enter the BASICA
  92. interpreter, you could add that key to the end of the KEY-FAKE command:
  93.  
  94.           KEY-FAKE "COLOR 14,1,1" 13 "CLS" 13 @61
  95.  
  96.      Suppose you have a terrific spelling checker called SpelRite.  The
  97. only problem is that it doesn't accept command line parameters.  Every
  98. time you run SpelRite, it asks you for the name of the file you want to
  99. check and the subdirectory where the dictionary is located.  You can
  100. fix this SpelRite problem with a two-line batch file called SR.BAT:
  101.  
  102.           KEY-FAKE "%1" 13 "\SPELRITE" 13
  103.           SPELRITE
  104.  
  105. When you enter SR followed by a filename, the name will be substituted
  106. for %1 when the batch file executes.  KEY-FAKE then answers the two
  107. questions for you.
  108.  
  109.  
  110.  
  111.  
  112.      Suppose that WordStar on the office PC-XT is used by beginners and
  113. experts.  The beginners like a help level of 3, but the experts prefer
  114. a help level of 1.  Two batch files using KEY-FAKE solve the problem.
  115. The first one (called WSB.BAT), for the beginners, just loads WordStar:
  116.  
  117.           CD\WORDSTAR
  118.           WS
  119.  
  120. The second batch file, for the experts (WSE.BAT), is similar except
  121. that it supplies the WordStar keystrokes to change the help level from
  122. the main menu:
  123.  
  124.           CD\WORDSTAR
  125.           KEY-FAKE "H1"
  126.           WS
  127.  
  128.      Suppose you want to skip the opening "Include error messages?
  129. (Y/N)" prompt in Turbo Pascal.  Set up a batch file with KEY-FAKE
  130. called T.BAT:
  131.  
  132.           CD\TURBOPAS
  133.           KEY-FAKE "Y"
  134.           TURBO
  135.  
  136. No patch, no DEBUG, no hex addresses, no problems with different Turbo
  137. Pascal versions.  Just a simple Y typed by KEY-FAKE instead.
  138.  
  139.      How would you like to print several WordStar files using one batch
  140. command.  Call this file WSP.BAT:
  141.  
  142.           CD\WORDSTAR
  143.           :CHECK
  144.           IF /%1==/ GOTO END
  145.           KEY-FAKE "P%1" 27 "X"
  146.           WS
  147.           SHIFT
  148.           GOTO CHECK
  149.           :END
  150.  
  151. You execute it by typing:  WSP file1 file2 file3 .....
  152.  
  153.      WSP.BAT uses the IF statement to check whether a program is
  154. present.  If so, the filename parameter is substituted for %1 in the
  155. KEY-FAKE command.  When WordStar begins executing, the first keystrokes
  156. it gets are P (for Print), the filename, as Esc (decimal 27), and X
  157. (for Exit).  WordStar won't exit until it has finished printing.  When
  158. it exits back to the batch file, WSP.BAT does a SHIFT command, making
  159. %1 the next file in the list, and goes through the routine again.
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.      Some programs, like Lotus's 1-2-3, clear out the keyboard buffer
  168. when they load.  This would ordinarily be a problem with KEY-FAKE, but
  169. KEY-FAKE has it licked.  When the digit 0 appears in a KEY-FAKE
  170. parameter, it takes on special meaning.  If a program checks to see
  171. if any keys are waiting, KEY-FAKE will say "No."  The program thinks
  172. that no keys are available and the buffer is clear.  When the program
  173. checks again, KEY-FAKE says "Yes" and delivers the next keystroke.
  174.  
  175.      Since virtually every time you enter 1-2-3 you do a File Retrieve
  176. command, a batch file (L.BAT) will load Lotus in a hurry:
  177.  
  178.           CD\LOTUS
  179.           KEY-FAKE 0 13 0 13 0 13 0 13 0 13 "/FR"
  180.           LOTUS
  181.  
  182. Make sure you have the system disk in drive A: before you run this one.
  183. The string of 0's and 13's was developed empirically, but it works
  184. well, skipping past the Lotus Access System Menu right into 1-2-3,
  185. ready to select a file.  Use KEY-FAKE and you'll have to be really
  186. quick if you want to read the copyright notice one more time.
  187.  
  188.      KEY-FAKE also helps out with some odd-ball batch file problems
  189. that may be difficult to handle with other methods.  For instance,
  190. suppose you have a batch file that changes the subdirectory, but at
  191. the end of the batch file you want to return to the directory from
  192. which it was executed.  The top of the batch file could save the
  193. subdirectory with the following commands:
  194.  
  195.           KEY-FAKE "CD" 26 13
  196.           COPY CON \RETDIR.BAT
  197.           CD >> \RETDIR.BAT
  198.  
  199. Here, KEY-FAKE supplies input to the subsequent COPY command.  The
  200. keystrokes are CD, a blank, a decimal 26 (Ctrl-Z or End-of-File), and
  201. a 13 (Enter).  With these keystrokes, COPY creates a file called
  202. RETDIR.BAT in the root directory.  This file contains only the
  203. characters CD and a blank.  Then, when the CD command is executed in
  204. the third line, its output (the current directory name) is redirected
  205. and appended to the RETDIR.BAT file.  Note the use of the double angle
  206. brackets for appending to a file rather than recreating it.
  207.  
  208.      Now you have a file called RETDIR.BAT in the root directory that
  209. contains a CD command to return to the current subdirectory.  The end
  210. of the batch file simply contains the following commands:
  211.  
  212.           CD \
  213.           RETDIR
  214.  
  215. This will then execute the batch file and return you to the
  216. subdirectory from which you started.
  217.  
  218.  
  219.  
  220.  
  221.  
  222.      You could even develop KEY-FAKE parameters that carry programs
  223. through an entire task.  For instance, you could import an ASCII table
  224. of numbers into 1-2-3, save it as a worksheet file, exit to the Lotus
  225. Access System Menu, convert the 1-2-3 file to a .DIF file, and then
  226. run a BASIC program that used the .DIF file, all by executing one
  227. batch file.
  228.  
  229.      Thus, if you have some applications involving several PC programs
  230. that you'd like to automate but that now require manual keystrokes,
  231. then KEY-FAKE may be just the answer.
  232.  
  233.      To recap the syntax, then, KEY-FAKE accepts anything within a pair
  234. of single or double quotes as normal keystrokes.  ASCII codes are
  235. specified by decimal numbers.  Decimal numbers preceded by the @ symbol
  236. are extended ASCII codes.  A zero (0) is a special code to signal to
  237. programs that the keyboard buffer is clear.  Anything else in the
  238. KEY-FAKE parameter is interpreted as "white space" delimiting valid
  239. parameters.  The KEY-FAKE program does no real error checking.
  240.  
  241.      Naturally, there are some limitations with KEY-FAKE.  The first
  242. is the length of the parameter.  PC-DOS limits command line parameters
  243. to 127 characters, including the blank that separates the parameter
  244. from the program name and the final carriage return.  This limits the
  245. number of keystrokes that KEY-FAKE can fake.  If the entire KEY-FAKE
  246. parameter is a string beginning with a quote and you leave out the
  247. final quote and you leave out the final quote (which is allowable),
  248. you'll be able to squeeze in 124 keystrokes.
  249.  
  250.      If a KEY-FAKE command is executed before a previous KEY-FAKE
  251. command has exhausted its stored keystrokes, the second execution will
  252. write over the remaining keystrokes from the first.  Watch out for
  253. this if you're nesting batch file executions.
  254.  
  255.      Some program get keyboard information directly from the hardware
  256. keyboard interrupt and will thus bypass KEY-FAKE.  Until XyQuest fixes
  257. their word processor (or comes out with a new version), KEY-FAKE will
  258. be entirely ignored by XyWrite II.
  259.  
  260.      Some programs continuously monitor the keyboard and retrieve
  261. keystrokes even if they are not able to use the keystrokes immediately.
  262. This means that you may find that KEY-FAKE will not work well when you
  263. are on-lien using a communications program.
  264.  
  265.      KEY-FAKE cannot simulate keystrokes not supported by the PC BIOS,
  266. such as Alt-Home.  Nor can it create different keystrokes for the two
  267. different Plus and Minus keys, which are used as separate commands by
  268. some program (most notably Framework).
  269.  
  270.      Although KEY-FAKE is a program that remains resident in memory,
  271. it may be executed an unlimited number of times during a single PC
  272. session.  KEY-FAKE only installs itself in memory the first time it
  273. is executed; subsequent executions take up no extra memory.
  274.  
  275.  
  276.  
  277.      The first time KEY-FAKE is run, it saves the vector address of
  278. Interrupt 16h and substitutes an address to its own routine.  It then
  279. decodes the parameter into keystrokes and saves them to its own
  280. internal buffer.  The decoding of the parameter accounts for about
  281. half of KEY-FAKE's code.
  282.  
  283.      Most large programs use Interrupt 16h to get keyboard information.
  284. (Smaller programs, like the DOS utilities, use the DOS Interrupt 21h to
  285. get keyboard information, but ultimately Interrupt 16h is invoked
  286. anyway.)  Normally, the PC's ROM BIOS answers an Interrupt 16h by just
  287. fishing keystrokes out of a small buffer that it maintains and handing
  288. them back to the calling program.  The keystrokes get in the buffer
  289. through the much more complex Interrupt 9h routine in the ROM BIOS.
  290. (Interrupt 9h is a hardware interrupt generated whenever a key is
  291. pressed.  The routine in the ROM BIOS gets the scan code of the key
  292. and must decode it into an ASCII or extended ASCII code before putting
  293. it in the keyboard buffer.)
  294.  
  295.      After KEY-FAKE is loaded, it intercepts Interrupt 16h calls and
  296. passes back keystrokes from its own internal buffer to the calling
  297. program.  When no more keystrokes are left, it simply lets the original
  298. Interrupt 16h operate normally.
  299.  
  300.      Subsequent executions of KEY-FAKE do not remain resident in
  301. memory.  KEY-FAKE searches through memory for its copyright notice.
  302. If it finds it, it knows that the program has been executed before.
  303. It then uses the keystroke buffer area allocated during the first
  304. execution and only has to decode the parameter.
  305.  
  306.      The best uses of KEY-FAKE will be those you cook up to automate
  307. your own applications.  Batch files are a big help in themselves, but
  308. KEY-FAKE really gives them a real boost in power.  And it's always
  309. nicer when your PC does your typing for you.
  310.